﻿using System;
using Assets.HSVPicker;
using UnityEngine;

// Token: 0x0200002D RID: 45
public class ColorPicker : MonoBehaviour
{
	// Token: 0x1700001E RID: 30
	// (get) Token: 0x060000E9 RID: 233 RVA: 0x0000C072 File Offset: 0x0000A272
	// (set) Token: 0x060000EA RID: 234 RVA: 0x0000C094 File Offset: 0x0000A294
	public Color CurrentColor
	{
		get
		{
			return new Color(this._red, this._green, this._blue, this._alpha);
		}
		set
		{
			if (this.CurrentColor == value)
			{
				return;
			}
			this._red = value.r;
			this._green = value.g;
			this._blue = value.b;
			this._alpha = value.a;
			this.RGBChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x060000EB RID: 235 RVA: 0x0000C0F4 File Offset: 0x0000A2F4
	private void Start()
	{
		this.Setup.AlphaSlidiers.Toggle(this.Setup.ShowAlpha);
		this.Setup.ColorToggleElement.Toggle(this.Setup.ShowColorSliderToggle);
		this.Setup.RgbSliders.Toggle(this.Setup.ShowRgb);
		this.Setup.HsvSliders.Toggle(this.Setup.ShowHsv);
		this.Setup.ColorBox.Toggle(this.Setup.ShowColorBox);
		this.HandleHeaderSetting(this.Setup.ShowHeader);
		this.UpdateColorToggleText();
		this.RGBChanged();
		this.SendChangedEvent();
	}

	// Token: 0x1700001F RID: 31
	// (get) Token: 0x060000EC RID: 236 RVA: 0x0000C1AB File Offset: 0x0000A3AB
	// (set) Token: 0x060000ED RID: 237 RVA: 0x0000C1B3 File Offset: 0x0000A3B3
	public float H
	{
		get
		{
			return this._hue;
		}
		set
		{
			if (this._hue == value)
			{
				return;
			}
			this._hue = value;
			this.HSVChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x17000020 RID: 32
	// (get) Token: 0x060000EE RID: 238 RVA: 0x0000C1D5 File Offset: 0x0000A3D5
	// (set) Token: 0x060000EF RID: 239 RVA: 0x0000C1DD File Offset: 0x0000A3DD
	public float S
	{
		get
		{
			return this._saturation;
		}
		set
		{
			if (this._saturation == value)
			{
				return;
			}
			this._saturation = value;
			this.HSVChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x17000021 RID: 33
	// (get) Token: 0x060000F0 RID: 240 RVA: 0x0000C1FF File Offset: 0x0000A3FF
	// (set) Token: 0x060000F1 RID: 241 RVA: 0x0000C207 File Offset: 0x0000A407
	public float V
	{
		get
		{
			return this._brightness;
		}
		set
		{
			if (this._brightness == value)
			{
				return;
			}
			this._brightness = value;
			this.HSVChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x17000022 RID: 34
	// (get) Token: 0x060000F2 RID: 242 RVA: 0x0000C229 File Offset: 0x0000A429
	// (set) Token: 0x060000F3 RID: 243 RVA: 0x0000C231 File Offset: 0x0000A431
	public float R
	{
		get
		{
			return this._red;
		}
		set
		{
			if (this._red == value)
			{
				return;
			}
			this._red = value;
			this.RGBChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x17000023 RID: 35
	// (get) Token: 0x060000F4 RID: 244 RVA: 0x0000C253 File Offset: 0x0000A453
	// (set) Token: 0x060000F5 RID: 245 RVA: 0x0000C25B File Offset: 0x0000A45B
	public float G
	{
		get
		{
			return this._green;
		}
		set
		{
			if (this._green == value)
			{
				return;
			}
			this._green = value;
			this.RGBChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x17000024 RID: 36
	// (get) Token: 0x060000F6 RID: 246 RVA: 0x0000C27D File Offset: 0x0000A47D
	// (set) Token: 0x060000F7 RID: 247 RVA: 0x0000C285 File Offset: 0x0000A485
	public float B
	{
		get
		{
			return this._blue;
		}
		set
		{
			if (this._blue == value)
			{
				return;
			}
			this._blue = value;
			this.RGBChanged();
			this.SendChangedEvent();
		}
	}

	// Token: 0x17000025 RID: 37
	// (get) Token: 0x060000F8 RID: 248 RVA: 0x0000C2A7 File Offset: 0x0000A4A7
	// (set) Token: 0x060000F9 RID: 249 RVA: 0x0000C2AF File Offset: 0x0000A4AF
	private float A
	{
		get
		{
			return this._alpha;
		}
		set
		{
			if (this._alpha == value)
			{
				return;
			}
			this._alpha = value;
			this.SendChangedEvent();
		}
	}

	// Token: 0x060000FA RID: 250 RVA: 0x0000C2CC File Offset: 0x0000A4CC
	private void RGBChanged()
	{
		HsvColor hsvColor = HSVUtil.ConvertRgbToHsv(this.CurrentColor);
		this._hue = hsvColor.normalizedH;
		this._saturation = hsvColor.normalizedS;
		this._brightness = hsvColor.normalizedV;
	}

	// Token: 0x060000FB RID: 251 RVA: 0x0000C30C File Offset: 0x0000A50C
	private void HSVChanged()
	{
		Color color = HSVUtil.ConvertHsvToRgb((double)(this._hue * 360f), (double)this._saturation, (double)this._brightness, this._alpha);
		this._red = color.r;
		this._green = color.g;
		this._blue = color.b;
	}

	// Token: 0x060000FC RID: 252 RVA: 0x0000C367 File Offset: 0x0000A567
	private void SendChangedEvent()
	{
		this.onValueChanged.Invoke(this.CurrentColor);
		this.onHSVChanged.Invoke(this._hue, this._saturation, this._brightness);
	}

	// Token: 0x060000FD RID: 253 RVA: 0x0000C398 File Offset: 0x0000A598
	public void AssignColor(ColorValues type, float value)
	{
		switch (type)
		{
		case ColorValues.R:
			this.R = value;
			break;
		case ColorValues.G:
			this.G = value;
			break;
		case ColorValues.B:
			this.B = value;
			break;
		case ColorValues.A:
			this.A = value;
			break;
		case ColorValues.Hue:
			this.H = value;
			break;
		case ColorValues.Saturation:
			this.S = value;
			break;
		case ColorValues.Value:
			this.V = value;
			break;
		}
	}

	// Token: 0x060000FE RID: 254 RVA: 0x0000C428 File Offset: 0x0000A628
	public float GetValue(ColorValues type)
	{
		switch (type)
		{
		case ColorValues.R:
			return this.R;
		case ColorValues.G:
			return this.G;
		case ColorValues.B:
			return this.B;
		case ColorValues.A:
			return this.A;
		case ColorValues.Hue:
			return this.H;
		case ColorValues.Saturation:
			return this.S;
		case ColorValues.Value:
			return this.V;
		default:
			throw new NotImplementedException(string.Empty);
		}
	}

	// Token: 0x060000FF RID: 255 RVA: 0x0000C498 File Offset: 0x0000A698
	public void ToggleColorSliders()
	{
		this.Setup.ShowHsv = !this.Setup.ShowHsv;
		this.Setup.ShowRgb = !this.Setup.ShowRgb;
		this.Setup.HsvSliders.Toggle(this.Setup.ShowHsv);
		this.Setup.RgbSliders.Toggle(this.Setup.ShowRgb);
		this.UpdateColorToggleText();
	}

	// Token: 0x06000100 RID: 256 RVA: 0x0000C514 File Offset: 0x0000A714
	private void UpdateColorToggleText()
	{
		if (this.Setup.ShowRgb)
		{
			this.Setup.SliderToggleButtonText.text = "RGB";
		}
		if (this.Setup.ShowHsv)
		{
			this.Setup.SliderToggleButtonText.text = "HSV";
		}
	}

	// Token: 0x06000101 RID: 257 RVA: 0x0000C56C File Offset: 0x0000A76C
	private void HandleHeaderSetting(ColorPickerSetup.ColorHeaderShowing setupShowHeader)
	{
		if (setupShowHeader == ColorPickerSetup.ColorHeaderShowing.Hide)
		{
			this.Setup.ColorHeader.Toggle(false);
			return;
		}
		this.Setup.ColorHeader.Toggle(true);
		this.Setup.ColorPreview.Toggle(setupShowHeader != ColorPickerSetup.ColorHeaderShowing.ShowColorCode);
		this.Setup.ColorCode.Toggle(setupShowHeader != ColorPickerSetup.ColorHeaderShowing.ShowColor);
	}

	// Token: 0x040001EF RID: 495
	private float _hue;

	// Token: 0x040001F0 RID: 496
	private float _saturation;

	// Token: 0x040001F1 RID: 497
	private float _brightness;

	// Token: 0x040001F2 RID: 498
	private float _red = 1f;

	// Token: 0x040001F3 RID: 499
	private float _green;

	// Token: 0x040001F4 RID: 500
	private float _blue;

	// Token: 0x040001F5 RID: 501
	private float _alpha = 1f;

	// Token: 0x040001F6 RID: 502
	[Header("Setup")]
	public ColorPickerSetup Setup;

	// Token: 0x040001F7 RID: 503
	[Header("Event")]
	public ColorChangedEvent onValueChanged = new ColorChangedEvent();

	// Token: 0x040001F8 RID: 504
	public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
}
